package com.liang.subject.domain.handler.subject;

import com.liang.subject.common.enums.SubjectInfoTypeEnum;
import com.liang.subject.domain.convert.BriefSubjectConverter;
import com.liang.subject.domain.entity.SubjectInfoBO;
import com.liang.subject.domain.entity.SubjectOptionBO;
import com.liang.subject.infra.basic.entity.SubjectBrief;
import com.liang.subject.infra.basic.service.SubjectBriefService;
import com.liang.subject.infra.basic.service.SubjectMappingService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 简答题策略类
 */
@Component
@RequiredArgsConstructor
public class BriefTypeHandler implements SubjectTypeHandler {

    private final SubjectBriefService subjectBriefService;
    @Override
    public SubjectInfoTypeEnum getSubjectType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void save(SubjectInfoBO subjectInfoBO) {
        // 简答题的插入
        SubjectBrief subjectBrief = BriefSubjectConverter.INSTANCE.convertBO2PO(subjectInfoBO);
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBriefService.save(subjectBrief);
    }

    @Override
    public SubjectOptionBO querySubjectInfo(Long subjectId) {
        SubjectBrief subjectBrief = subjectBriefService.getBySubjectId(subjectId);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return subjectOptionBO;
    }
}
